package ru.eas.structure;

import java.util.Scanner;

/**
 * @author aesipov
 */
public class DisjointSets {

    public static void main(String[] args) {
//        String testString = "5 7\n" +
//                "Check 1 2\n" +
//                "Union 1 2\n" +
//                "Check 1 2\n" +
//                "Union 5 1\n" +
//                "Check 5 2\n" +
//                "Check 3 3\n" +
//                "Check 3 4";
//        Scanner scanner = new Scanner(testString);

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        DisjointSets disjointSets = new DisjointSets(n);

        int commandCount = scanner.nextInt();
        for (int i = 0; i < commandCount; i++) {
            String command = scanner.next();
            if ("Check".equals(command)) {
                int set1 = disjointSets.find(scanner.nextInt());
                int set2 = disjointSets.find(scanner.nextInt());
                System.out.println(set1 == set2 ? "True" : "False");
            } else if ("Union".equals(command)) {
                int element1 = scanner.nextInt();
                int element2 = scanner.nextInt();
                disjointSets.union(element1, element2);
            }
        }
    }
    
    private int[] parents;

    public DisjointSets(int setCount) {
        this.parents = new int[setCount + 1];
        for (int i = 0; i < parents.length; i++) {
            parents[i] = i;
        }
    }

    private void union(int element1, int element2) {
        int set1 = find(element1);
        int set2 = find(element2);
        if (set1 == set2) {
            return;
        }
        parents[set1] = set2; //hang set1 to set2
    }

    private int find(int element) {
        int parent = parents[element];
        if (element != parent) {
            parents[element] = find(parent);
        }
        return parents[element];
    }
}
